package com.example.leave.controller;

import com.example.leave.common.CommonPage;
import com.example.leave.common.CommonResult;
import com.example.leave.dto.ChangeHistory;
import com.example.leave.dto.LeaveFormOperationHistoryDto;
import com.example.leave.form.IdAndPageInfoForm;
import com.example.leave.form.IdAndTimeBetweenAndPageInfoVoForm;
import com.example.leave.service.LeaveFormOperationHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.List;

/**
 * @author huangguibo
 */
@Api(tags = "请假表单变更履历信息管理")
@Controller
@RequestMapping("/LeaveFormOperationHistory")
public class LeaveFormOperationHistoryController {
    @Autowired
    LeaveFormOperationHistoryService leaveFormOperationHistoryService;

    @PostMapping(value = "findByUserId")
    @ResponseBody
    @ApiOperation("通过用户id查找请假表单履历信息")
    CommonResult<CommonPage<LeaveFormOperationHistoryDto>> findByUserId(@RequestBody @Valid IdAndPageInfoForm userIdAndPageInfoForm) {
        return CommonResult.success(leaveFormOperationHistoryService.findByUserId(userIdAndPageInfoForm), "查询成功");
    }

    @PostMapping(value = "findByOperatorAndOperationTimeBetween")
    @ResponseBody
    @ApiOperation("通过操作者和操作时间区间查找请假表单履历信息")
    CommonResult<CommonPage<LeaveFormOperationHistoryDto>> findByOperatorAndOperationTimeBetween
            (@RequestBody @Valid IdAndTimeBetweenAndPageInfoVoForm operatorIdAndTimeBetweenAndPageInfoVo) {
        return CommonResult.success(leaveFormOperationHistoryService
                .findByOperatorAndOperationTimeBetween(operatorIdAndTimeBetweenAndPageInfoVo), "查询成功");
    }

    @PostMapping(value = "findByLeaveFormId")
    @ResponseBody
    @ApiOperation("通过表单id查找请假表单履历信息")
    CommonResult<CommonPage<LeaveFormOperationHistoryDto>> findByLeaveFormId
            (@RequestBody @Valid IdAndPageInfoForm idAndPageInfoForm) {
        return CommonResult.success(leaveFormOperationHistoryService.findByLeaveFormId(idAndPageInfoForm), "查询成功");
    }

    @PostMapping(value = "findChangeByLeaveFormId")
    @ResponseBody
    @ApiOperation("通过表单id查找该请假表单详细变更信息")
    public CommonResult<List<ChangeHistory>> findChangeByLeaveFormId(@Valid @RequestBody IdAndPageInfoForm idAndPageInfoForm) {
        return CommonResult.success(leaveFormOperationHistoryService.findChangeByLeaveFormId(idAndPageInfoForm), "查询成功");
    }

}
